using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Xml;

namespace Customs.Components.SXXK.ThanhKhoan
{
    /// <summary>
    /// chua cac phuong thuc de lay thong tin luong npl tai xuat, ton dau va ton cuoi cua tung to khai sau tung lan thanh ly cua tung to khai tai xuat
    /// </summary>
    public class ThongTinTonNPLTaiXuat
    {
        public static DataSet GetTonNPLTaiXuatOfLanThanhLy(string maHaiQuan, string maDoanhNghiep, int lanthanhly)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT     dbo.DNPLTXUAT_TL.LAN_TL, dbo.DNPLTXUAT_TL.MA_DV, dbo.DNPLTXUAT_TL.SOTK, dbo.DNPLTXUAT_TL.MA_LH, dbo.DNPLTXUAT_TL.NAMDK,  " +
                           "dbo.DNPLTXUAT_TL.MA_HQ, dbo.DNPLTXUAT_TL.MA_NPL, dbo.DNPLTXUAT_TL.LUONG, dbo.DNPLTXUAT_TL.TON_DAU, dbo.DNPLTXUAT_TL.TON,  " +
                           "dbo.DNPLTXUAT.LUONG AS LuongXuat, dbo.DNPLTXUAT.TON AS TonXuat " +
                           "FROM         dbo.DNPLTXUAT INNER JOIN " +
                           "dbo.DNPLTXUAT_TL ON dbo.DNPLTXUAT.SOTK = dbo.DNPLTXUAT_TL.SOTK AND dbo.DNPLTXUAT.MA_LH = dbo.DNPLTXUAT_TL.MA_LH AND " +
                           "dbo.DNPLTXUAT.NAMDK = dbo.DNPLTXUAT_TL.NAMDK AND dbo.DNPLTXUAT.MA_HQ = dbo.DNPLTXUAT_TL.MA_HQ AND " +
                           "dbo.DNPLTXUAT.MA_NPL = dbo.DNPLTXUAT_TL.MA_NPL " +
                           "where dbo.DNPLTXUAT_TL.LAN_TL=@LAN_TL and dbo.DNPLTXUAT_TL.MA_DV=@Ma_DV and dbo.DNPLTXUAT_TL.MA_HQ=@Ma_HQ";

            SqlParameter[] parameters = new SqlParameter[3];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@Ma_DV", SqlDbType.VarChar);
            parameters[1].Size = 14;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maDoanhNghiep;

            parameters[2] = new SqlParameter("@LAN_TL", SqlDbType.Int);
            parameters[2].Direction = ParameterDirection.Input;
            parameters[2].Value = lanthanhly;

            DataSet ds = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);
            return ds;
        }
        public static DataSet GetTonNPLTaiXuat(string maHaiQuan, string maDoanhNghiep)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT     dbo.DNPLTXUAT_TL.LAN_TL, dbo.DNPLTXUAT_TL.MA_DV, dbo.DNPLTXUAT_TL.SOTK, dbo.DNPLTXUAT_TL.MA_LH, dbo.DNPLTXUAT_TL.NAMDK,  " +
                         "dbo.DNPLTXUAT_TL.MA_HQ, dbo.DNPLTXUAT_TL.MA_NPL, dbo.DNPLTXUAT_TL.LUONG, dbo.DNPLTXUAT_TL.TON_DAU, dbo.DNPLTXUAT_TL.TON,  " +
                         "dbo.DNPLTXUAT.LUONG AS LuongXuat, dbo.DNPLTXUAT.TON AS TonXuat " +
                         "FROM         dbo.DNPLTXUAT INNER JOIN " +
                         "dbo.DNPLTXUAT_TL ON dbo.DNPLTXUAT.SOTK = dbo.DNPLTXUAT_TL.SOTK AND dbo.DNPLTXUAT.MA_LH = dbo.DNPLTXUAT_TL.MA_LH AND " +
                         "dbo.DNPLTXUAT.NAMDK = dbo.DNPLTXUAT_TL.NAMDK AND dbo.DNPLTXUAT.MA_HQ = dbo.DNPLTXUAT_TL.MA_HQ AND " +
                         "dbo.DNPLTXUAT.MA_NPL = dbo.DNPLTXUAT_TL.MA_NPL " +
                         "where dbo.DNPLTXUAT_TL.MA_DV=@Ma_DV and dbo.DNPLTXUAT_TL.MA_HQ=@Ma_HQ";

            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@Ma_DV", SqlDbType.VarChar);
            parameters[1].Size = 14;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maDoanhNghiep;

            DataSet ds = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);
            return ds;
        }
    }
}
